import allure
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webdriver import WebDriver

from src.day36.pages.add_department import AddDepartment
from src.day36.pages.base_page import BasePage


class ContactPage(BasePage):
    __PLUS_ICON = (By.CSS_SELECTOR, '.member_colLeft_top_addBtnWrap.js_create_dropdown')
    __DEPARTMENT_ADD = (By.CSS_SELECTOR, '.js_create_party')
    __DEPARTMENT_LIST = (By.CSS_SELECTOR, '.jstree-anchor')


    def goto_add_department(self):
        """
        添加部门
        :return:
        """
        with allure.step("进入添加部门的页面"):
            self.find_and_click(*self.__PLUS_ICON)
            self.find_and_click(*self.__DEPARTMENT_ADD)
        return AddDepartment(self.driver)


    def get_departments_list(self):
        """
        返回部门列表
        :return:
        """
        with allure.step("获取部门列表"):
            el_list = self.driver.find_elements(By.CSS_SELECTOR, '.jstree-anchor')
            department_list = [el.text for el in el_list]
        return department_list